package com.csdn.listener;

import com.csdn.config.BaseConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.monitor.FileAlterationListener;
import org.apache.commons.io.monitor.FileAlterationObserver;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Set;

@Slf4j
@Component
public class FileListener implements FileAlterationListener {

    Set<Class<? extends BaseConfig>> collects;

    public FileListener(Set<Class<? extends BaseConfig>> collects) {
        this.collects = collects;
    }

    @Override
    public void onStart(FileAlterationObserver fileAlterationObserver) {
        File directory = fileAlterationObserver.getDirectory();
        //log.info("开始监听..." + directory);
    }

    @Override
    public void onDirectoryCreate(File file) {
        // log.info("目录被创建了...");
    }

    @Override
    public void onDirectoryChange(File file) {
        //log.info("目录被修改了...");
    }

    @Override
    public void onDirectoryDelete(File file) {
        // log.info("目录被删除了...");
    }

    @Override
    public void onFileCreate(File file) {
        log.info("文件被创建了...");
    }

    @Override
    public void onFileChange(File file) {
        log.info("文件被修改了...");
    }

    @Override
    public void onFileDelete(File file) {
        log.info("文件被删除了...");
    }

    @Override
    public void onStop(FileAlterationObserver fileAlterationObserver) {
        File directory = fileAlterationObserver.getDirectory();
        // log.info("结束监听..." + directory);
    }
}
